package address.model;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import board.util.Utilities;

import to.AddressTO2;

public class AddressDAO {
	private SqlMapClientTemplate sqlMap;
	public AddressDAO(SqlMapClientTemplate sqlMap){
		this.sqlMap = sqlMap;
	}
	
//	public void insertAddress(AddressTO ato) throws SQLException{
//		sqlMap.insert("insertAddress", ato);
//	}
//	
//	public void updateAddress(AddressTO ato) throws SQLException{
//		sqlMap.update("updateAddress", ato);
//	}
//	
//	
//	@SuppressWarnings("unchecked")
//	public ArrayList<AddressTO> selectAllAddress(HashMap<String,Object> condition) throws SQLException{
//		return (ArrayList<AddressTO>) sqlMap.queryForList("selectAllAddress",condition);
//	}
//	public AddressTO selectAddressByMemberPhone(String memberPhone) throws SQLException{
//		return (AddressTO)sqlMap.queryForObject("selectAddressByMemberPhone",memberPhone);
//	}

	//board테이블에 내용을 하나 insert
		public Object insertContentForNewCount(AddressTO2 ato) throws SQLException{
			return sqlMap.insert("insertAddress", ato);
								 
		}
		public Object insertContentForReply(AddressTO2 ato) throws SQLException{
			return sqlMap.insert("insertContentForReply3", ato);
		}
		public ArrayList<AddressTO2> selectBoardListByPage(int page) throws SQLException{
			HashMap map = new HashMap();
			map.put("contentPerPage", Utilities.CONTENT_PER_PAGE);
			map.put("page", page);
			return (ArrayList<AddressTO2>)sqlMap.queryForList("selectAddressListByPage", map);
		}
		//페이징 없이 전체 조회
		public ArrayList<AddressTO2> selectBoardAllList() throws SQLException{
			return (ArrayList<AddressTO2>)sqlMap.queryForList("selectAddressAllList");
		}
		
		//총 게시물 수를 return 하는 메소드
		public int selectTotalContent() throws SQLException{
			return (Integer)sqlMap.queryForObject("selectTotalContent3");
		}
		public int updateViewCount(int no) throws SQLException{
			return sqlMap.update("updateViewCount3", no);
		}

		public AddressTO2 selectContentByNO(int no) throws SQLException{
			return (AddressTO2)sqlMap.queryForObject("selectContentByNO3", no);
		}
		//게시물 정보를 수정하는 메소드
		public int updateContent(AddressTO2 ato) throws SQLException{
			return sqlMap.update("updateContent3", ato);
		}
		//글번호로 글을 삭제하는 메소드
		public int deleteContentByNO(int no) throws SQLException{
			return sqlMap.delete("deleteContentByNO3", no);
		}
		//답변 처리시 restep값 update하는 메소드
		public int updateRestep(int refamily, int restep) throws SQLException{
			HashMap<String, Integer> map = new HashMap<String, Integer>();
			map.put("refamily", refamily);
			map.put("restep", restep);
			return sqlMap.update("updateRestep3", map);
		}
		
}
